/*
	Copyright 2013 Roman Tudor

	This file is part of numbrsLib.

    numbrsLib is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    numbrsLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with numbrsLib.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * The main package.
 */
package roman.tudor.numbrsLib;

/**
 * A class with a boolean and a function.<br />
 * The boolean returns true if 25(example) dots can arrange in a full square, and false if not,<br />
 * and the function draws the square.
 * @author <a href="http://romantudorioan.wordpress.com">Tudor Roman</a>
 * @version 2.0
 * @since september 9 2013
 */
public class FullSquare {
	/**
	 * Returns true if 25(example) dots can arrange in a full square, and false if not.
	 * @param n The number (25 in our example)
	 * @return True if 25(example) dots can arrange in a full square, and false if not
	 */
	
	static String temp = "";
	
	public static boolean isFullSquare(double n){
		if (n % 1 == 0.0){
			n = (int)n;
		}
		if (Math.sqrt(n) % 1 == 0.0){
			return true;
		}
		else{
			return false;
		}
	}
	
	/**
	 * Draws the square, made of dots, if possible.
	 * @param n The number of dots.
	 */
	public static void drawSquare(double n){
		boolean isFullSquare2;
		int width = 0;
		int height = 0;
		double n1 = Math.sqrt(n);
		
		if (n - (int)(n) != 0.0){
			n = (int)n;
		}
		if (n1 - (int)n1 == 0.0){
			isFullSquare2 = true;
			width = (int) n1;
			height = (int) n1;
		}
		else{
			isFullSquare2 = false;
		}
		
		if (isFullSquare2 = false){
			System.out.println("Cannot draw the square!");
		}
		
		while(isFullSquare2 == true && width != 0 && height != 0){
				if (width != 0 && height != 0){
					System.out.print("* ");
					width--;
					if (width == 1){
						System.out.print("*");
						height--;
						width = (int)n1;
						System.out.println("");
					}
				}
		}
		}
	public static String Square(double n){
		boolean isFullSquare2;
		int width = 0;
		int height = 0;
		double n1 = 0;
		
		if (n % 1 == 0.0){
			n1 = (int)n;
		}
		if (n1 % 1 == 0.0){
			isFullSquare2 = true;
			width = (int) n1;
			height = (int) n1;
		}
		else{
			isFullSquare2 = false;
		}
		
		if (isFullSquare2 = false){
			System.out.println("Cannot draw the square!");
		}
		
		while(isFullSquare2 == true && width != 0 && height != 0){
				if (width != 0 && height != 0){
					temp = temp + "* ";
					width--;
					if (width == 1){
						temp = temp + "*\n";
						height--;
						width = (int)n1;
					}
				}
		}
		return temp;
		}
}
